<template>
    <div class="risk">
   
      <eagle-tab-page-list
        url="DangerReportJG/GetPageQueryData"
        :params="params"
        :filterParams="filterParams"
        :filterTab="filterTab"
        @initActive="_initActive"
        @initList="_initList"
        ref="eagleTabPageList"
      >
   
  
          <div class="tab-content">
            <van-list :finished="finished" v-model="loading" @load="onLoad">
              <eagle-cell
                class="mb-10 mt-10 br-8"
                v-for="(item, index) in list"
                :key="index"
              >
                <div class="warn_item">
                  <div>
                    <div class="dep_sort_name">{{ item.Name }}</div>
  
                    <eagle-row gutter="20" class="dep_sort">
                      <eagle-col span="24">
                        <img
                          src="@/assets/Images/AppIcon/icon_list_type.png"
                          alt=""
                        />{{ item.CheckTypeName }}
                      </eagle-col>
                    </eagle-row>
                    <eagle-row gutter="20" class="dep_sort">
                      <eagle-col span="24">
                        <img
                          src="@/assets/Images/AppIcon/icon_list_kind.png"
                          alt=""
                        />{{ item.ReportName || "" }}
                      </eagle-col>
                    </eagle-row>
                    <eagle-row gutter="20" class="dep_sort">
                      <eagle-col span="10">
                        <img
                          src="@/assets/Images/AppIcon/icon_equ_type.png"
                          alt=""
                        />{{
                          item.ReportType==1? "检查报告":"整改报告"
                        }}
                      </eagle-col>
                      <eagle-col span="14">
                        <img
                          src="@/assets/Images/AppIcon/icon_list_danger.png"
                          alt=""
                        />隐患：{{ item.HiddenDangerCnt }}
                      </eagle-col>
                    </eagle-row>
                    <eagle-row gutter="20" class="dep_sort">
                      <eagle-col span="10">
                        <img
                          src="@/assets/Images/AppIcon/icon_list_user.png"
                          alt=""
                        />{{ item.CreateChnName }}
                      </eagle-col>
                      <eagle-col span="14">
                        <img
                          src="@/assets/Images/AppIcon/icon_list_date.png"
                          alt=""
                        />{{ item.CreateDate | formatDateTime }}
                      </eagle-col>
                    </eagle-row>
                  </div>
                </div>
                <div class="look-report" @click="lookPdf(item)">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_review.png"
                    alt=""
                  />
                  <span>查看报告</span>
                </div>
              </eagle-cell>
            </van-list>
          </div>
      </eagle-tab-page-list>
    </div>
  </template>
  
  <script>
  import { getDate } from "@/utils/getDate";
  import deepClone from '../../../utils/deepClone';
  export default {
    data() {
      return {
        title: "",
        active: 0,
        value: "",
        list: [],
        filter: {
          page: 0,
          dataType: "ReportHistory",
          conditions:''
        },
        loading: false,
        finished: false,
        baseUrl: process.env.VUE_APP_BASE_API,
        tabTitle: [{ title: "报告历史" }],
        params: [
          {
            title: "报告历史",
            dataType: "taskreportlist",
          }
        ],
        value1:0,
        value2:'a',
        option1: [
          { text: '全部', value: 0 },
          { text: '检查报告', value: 1 },
          { text: '整改报告', value: 2 },
        ],
        option2: [
          { text: '全部', value: 'a' },
          { text: '通用隐患整改报告', value: 'b' },
          { text: '通用隐患检查报告', value: 'c' },
        ],
        filterParams:[],
        filterTab: true,
     filterParams2:[
       {
              name: "ReportType",
              title: "全部",
              originTitle: "全部",
              dataType: "int",
              data: [
                { text: "全部", value: "" },
                { text: "检查报告", value: "1" },
                { text: "整改报告", value: "2" },
              ],
            },
            {
              name: "ReportCode",
              title: "全部",
              originTitle: "全部",
              dataType: "string",
              data: [
              { text: "全部", value: "" },
              ],
            },
          ]
      };
  
    },
    created() {
        this.params[0].ctCode=this.$route.query.ctCode;
    //   this.getParams()
    },
    methods: {
      _initActive(active) {
        this.active = active;
        this.filterTab = active==0?false:true;
        this.filterParams=this.filterParams2
        
      },
      _initList(list) {
        this.list = list;
      },
      onSearch() {
        this.filter.page = 0;
        this.filter.keywords = this.value;
        this.getList();
      },
      clearSearch() {
        this.filter.page = 0;
        this.filter.keywords = "";
        this.getList();
      },
      changeTabs(active) {
        this.active = active;
        this.filter.page = 0;
        this.getList();
      },
      getList(value) {
        this.loading = true;
        let _this = this;
  
        // 筛选
        _this.filter.conditions=JSON.stringify([{IsTemp:false,
              Name:"ReportCode",
              Operator:"\u003d",
              Value:value}])
            
        console.log(_this.filter.conditions)
        
        _this.$axios
          .get("/DangerReport/GetPageData", { params: _this.filter })
          .then((res) => {
            _this.loading = false;
            if (!res.data.HasNextPage) {
              _this.finished = true;
            }
            _this.list = res.data.Data;
            _this.filter.page = res.data.PageIndex;
            
          });
          console.log('222',this.list)
      },
      onLoad() {
        console.log('load')
        this.loading = true;
        ++this.filter.page;
        let _this = this;
        _this.$axios
          .get("/DangerReport/GetPageData", { params: _this.filter })
          .then((res) => {
            _this.loading = false;
            res.data.Data.forEach((item) => {
              item.CreateDate = getDate(item.CreateDate);
            });
            _this.filter.page = res.data.PageIndex;
            _this.list = _this.list.concat(res.data.Data);
            if (!res.data.HasNextPage) {
              _this.finished = true;
            }
          });
      },
  
      // 检查报告
      _goTaskReport() {
        this.title = "生成检查报告(按任务)";
        this.$router.push({
          path: "/Danger/TaskReport",
          query: { type: "Report", reportType: "1" },
        });
      },
      // 隐患生成
      _goHiddenDangerReport() {
        this.title = "生成检查报告(按隐患)";
        this.$router.push({
          path: "/Danger/HiddenDangerReport",
          query: { type: "ReportTaskDetail", reportType: "1" },
        });
      },
      // 整改报告
      _goCorrectiveReport() {
        this.title = "生成整改报告(按任务)";
        this.$router.push({
          // path: '/Danger/TaskReport',
          path: "/Danger/CorrectiveReport",
          query: { type: "Report", reportType: "2" },
        });
      },
      // 整改隐患
      _goCorrectiveReportByDanger() {
        this.title = "生成整改报告(按隐患)";
        this.$router.push({
          // path: '/Danger/HiddenDangerReport',
          path: "/Danger/CorrectiveHiddenDanger",
          query: { type: "ReportTaskDetail", reportType: "2" },
        });
      },
      // 查看报告
      lookPdf(item) {
        // this.title = "报告详情"
        // this.$router.push("/Attach/AatachDetail?url=" + this.baseUrl + item.Attachs);
        // 打开新窗口
        // window.open(this.baseUrl + item.Attachs)
        console.log(111,item)
        this.title = "报告详情";
        this.$router.push({
          name: "CheckReportDetail",
          query: {
            // url: this.baseUrl + item.Attachs,
            url:
              // "https://afx.ehsway.com" +
              // "/Plugins/pdfjs/web/viewer.html?file=" +
              // item.Attachs,
              // "http://chsyat.safetyhua.com/"  +
              process.env.VUE_APP_BASE_API+
              item.Attachs,
              signState:item.SignState,
              id:item.ID,
              isSign:item.isSign
          },
        });
        
        
      },
      getParams(){
          //InfoReportDefine/GetDefines
          let _this = this;
          _this.$axios
          .get("/InfoReportDefine/GetDefines", { params: {jgType:"normal"}})
          .then((res) => {
           res.data.forEach((item)=>{
              item.text=item.Name
              item.value=item.ID
              console.log(item)
              _this.filterParams2[1].data.push(item)
           
            })
            
            
          });
         
        },
      menuChange1(value){
        if(value === 0){
          this.getList()
        }else if(value === 1){
          this.getList('DangerCheckReportRA')
        }else if(value === 2){
          this.getList('DangerCorrectiveReportRA')
        }
      },
      menuChange2(value){
        if(value === 'a'){
          this.getList()
        }else if(value === 'b'){
          this.getList('DangerCheckReportRA')
   
        }else if(value === 'c'){
          this.getList('DangerCorrectiveReportRA')
        
        }
      }
    },
  };
  </script>
  
  <style lang="less" scoped>
  .risk {
    background-color: #e8f1f8;
    .info_search {
      padding: 10px;
      border-radius: 5px !important;
      .van-field__control {
        background-color: #ffffff !important;
      }
    }
  }
  
  .tab-content {
    padding: 0 10px;
    font-size: 14px;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
  .look-report {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 10px;
  
    font-size: 12px;
    color: #666;
    border-top: 1px solid #eee;
  }
  .all_dep {
    background-color: #ffffff;
  }
  .warn_item {
    background-color: #ffffff;
    /*margin-bottom: 10px;*/
    // padding: 10px 0 10px 10px;
    border-radius: 5px;
    position: relative;
  }
  .warn_header {
    display: flex;
    justify-content: space-between;
    position: relative;
    margin-bottom: 10px;
    .warn_tag {
      position: absolute;
      right: 0;
      top: 0;
      border-radius: 26.64rem 0 0 26.64rem;
    }
  }
  .dep_sort_name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  .dep_btm {
    display: flex;
    justify-content: flex-end;
    .btm_item {
      display: flex;
      align-items: center;
      img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
      }
    }
  }
  .report-list {
    height: 100vh;
    background-color: #fff;
    overflow: hidden;
  }
  .report-title {
    width: 100px;
    font-size: 15px;
    text-align: center;
    margin: 40px auto;
    padding-bottom: 10px;
    border-bottom: 1px solid #ccc;
  }
  .report-btns {
    margin-top: 10px;
    padding: 0 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .submit-btn {
      width: 40%;
      height: 35px;
      font-size: 14px;
    }
  }
  </style>
  